package com.fzs.sshd.cli.server.shell;

import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.shell.ProcessShellFactory;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class BashInteractiveProcessShellFactory extends ProcessShellFactory {
    public static final BashInteractiveProcessShellFactory INSTANCE = new BashInteractiveProcessShellFactory();

    public BashInteractiveProcessShellFactory() {
        super(getCommandStr(), getElementsStr());
        System.out.println("use interactiveBashProcessShellFactory...");
    }

    @Override
    protected List<String> resolveEffectiveCommand(
            ChannelSession channel, String rawCommand, List<String> parsedElements) {
        return parsedElements;
    }

    private static String getCommandStr() {
        return OsUtils.isWin32() ? "PowerShell.exe" : "/bin/bash -i -l";
    }

    private static List<String> getElementsStr() {
        return OsUtils.isWin32() ? Collections.singletonList("PowerShell.exe") : Collections.unmodifiableList(Arrays.asList("/bin/bash", "-i", "-l"));
    }

}
